package com.beidouin.GnssMain.sample;


import android.app.Activity;
import android.app.Service;
import android.os.Vibrator;
import com.baidu.mapapi.SDKInitializer;
import com.beidouin.GnssMain.FileManager;
import com.beidouin.GnssMain.SerialPortReader;
import com.beidouin.GnssMain.models.PilotInfo;
import com.beidouin.GnssMain.service.LocationService;
import java.util.ArrayList;
import java.util.List;

public class Application extends android.app.Application {

	public LocationService locationService;
	public Vibrator mVibrator;

	private List<Activity> activities = new ArrayList<Activity>();

	@Override
	public void onCreate() {
		super.onCreate();
		instance = this;
		PilotInfo.init();
		SerialPortReader.init();
		FileManager.getInstance().initFileList();
		locationService = new LocationService(getApplicationContext());
		mVibrator =(Vibrator)getApplicationContext().getSystemService(Service.VIBRATOR_SERVICE);
		SDKInitializer.initialize(getApplicationContext());

	}

	private static Application instance;

	public static Application getInstance() { return instance; }

	public void addActivity(Activity activity) {
		activities.add(activity);
	}

	@Override
	public void onTerminate() {
		super.onTerminate();

		for (Activity activity : activities) {
			activity.finish();
		}

		System.exit(0);
	}


}
